# -*- coding: utf-8 -*-
import scrapy
import json
from ..items import QcjobItem


class QcwycrawlerSpider(scrapy.Spider):
    name = 'qcjob'
    start_urls = []
    url = 'https://search.51job.com/list/000000,000000,0000,32,9,99,+,2,{}.html'
    for i in range(1, 1001):
        start_urls.append(url.format(i))

    def parse(self, response):
        job_list = response.xpath("/html/body/script[2]/text()").extract_first()[29:]
        job_list = json.loads(job_list)
        item = QcjobItem()
        for job in job_list['engine_search_result']:
            # print(job)
            item['job_name'] = job['job_name']
            item['job_salary'] = job['providesalary_text']
            item['job_area'] = job['workarea_text']
            item['requirement'] = job['attribute_text']
        yield item